<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    利用 Shell 脚本实现邮件监控 Linux 系统的内存.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-linux/利用 Shell 脚本实现邮件监控 Linux 系统的内存"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  利用 Shell 脚本实现邮件监控 Linux 系统的内存.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/linux/%E5%88%A9%E7%94%A8%20Shell%20%E8%84%9A%E6%9C%AC%E5%AE%9E%E7%8E%B0%E9%82%AE%E4%BB%B6%E7%9B%91%E6%8E%A7%20Linux%20%E7%B3%BB%E7%BB%9F%E7%9A%84%E5%86%85%E5%AD%98/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/linux/">linux</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.5k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="利用-Shell-脚本实现邮件监控-Linux-系统的内存"><a href="#利用-Shell-脚本实现邮件监控-Linux-系统的内存" class="headerlink" title="利用 Shell 脚本实现邮件监控 Linux 系统的内存"></a>利用 Shell 脚本实现邮件监控 Linux 系统的内存</h1><h4 id="一、安装Linux下面的一个邮件客户端Msmtp软件-类似于一个Foxmail的工具"><a href="#一、安装Linux下面的一个邮件客户端Msmtp软件-类似于一个Foxmail的工具" class="headerlink" title="一、安装Linux下面的一个邮件客户端Msmtp软件(类似于一个Foxmail的工具)"></a>一、安装Linux下面的一个邮件客户端Msmtp软件(类似于一个Foxmail的工具)</h4><p>1、下载安装：<a target="_blank" rel="noopener" href="http://downloads.sourceforge.net/">http://downloads.sourceforge.net</a> … 206451&amp;big_mirror=0</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># tar jxvf msmtp-1.4.16.tar.bz2  </span><br><span class="line"># cd msmtp-1.4.16  </span><br><span class="line"># .&#x2F;configure --prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;msmtp  </span><br><span class="line"># make  </span><br><span class="line"># make install  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>2、创建msmtp配置文件和日志文件（host为邮件域名，邮件用户名test，密码123456）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"># vim ~&#x2F;.msmtprc  </span><br><span class="line">  </span><br><span class="line">account default   </span><br><span class="line">host 126.com   </span><br><span class="line">from test@126.com   </span><br><span class="line">auth login   </span><br><span class="line">user test   </span><br><span class="line">password 123456   </span><br><span class="line">logfile ~&#x2F;.msmtp.log  </span><br><span class="line">  </span><br><span class="line"># chmod 600 ~&#x2F;.msmtprc  </span><br><span class="line"># touch ~&#x2F;.msmtp.log  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>3、mutt安装配置：（一般linux下有默认安装mutt）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># vim ~&#x2F;.muttrc  </span><br><span class="line">  </span><br><span class="line">set sendmail&#x3D;&quot;&#x2F;usr&#x2F;local&#x2F;msmtp&#x2F;bin&#x2F;msmtp&quot;   </span><br><span class="line">set use_from&#x3D;yes   </span><br><span class="line">set real   </span><br><span class="line">set from&#x3D;test@126.com   </span><br><span class="line">set envelope_from&#x3D;yes   </span><br><span class="line">set rfc2047_parameters&#x3D;yes   </span><br><span class="line">set charset&#x3D;&quot;utf-8&quot; </span><br></pre></td></tr></table></figure>

<p>4、邮件发送测试（-s邮件标题，-a表加附件）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># echo &quot;邮件内容123456&quot; | mutt -s &quot;邮件标题测试邮件&quot; -a &#x2F;scripts&#x2F;test.txt test@126.com  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="二、使用Free命令监控系统内存"><a href="#二、使用Free命令监控系统内存" class="headerlink" title="二、使用Free命令监控系统内存"></a>二、使用Free命令监控系统内存</h4><p>1、使用free命令查看linux系统内存使用情况：（以M为单位）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># free -m   </span><br><span class="line">（执行结果如下样式）  </span><br><span class="line">total used free shared buffers cached  </span><br><span class="line">Mem: 3952 3414 538 0 168 484  </span><br><span class="line">-&#x2F;+ buffers&#x2F;cache: 2760 1191  </span><br><span class="line">Swap: 8191 86 8105  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>2、查看截取剩余内存free的数值命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">(1) 物理内存free值：# free -m | grep Mem | awk &#39;&#123;print $4&#125;&#39;  </span><br><span class="line">(2) 缓冲区的free值：# free -m | grep - | awk &#39;&#123;print $4&#125;&#39;  </span><br><span class="line">(3) Swap分区free值：# free -m | grep Swap | awk &#39;&#123;print $4&#125;&#39;  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>3、编写内存监控的脚本文件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"># vim &#x2F;scripts&#x2F;free-mem.sh  </span><br><span class="line">  </span><br><span class="line">#!&#x2F;bin&#x2F;bash   </span><br><span class="line">#使用free命令监控linux系统内存变化  </span><br><span class="line">  </span><br><span class="line">#取系统当前时间（以追加的方式写入文件&gt;&gt;）   </span><br><span class="line">date &gt;&gt; &#x2F;scripts&#x2F;date-time.txt  </span><br><span class="line">  </span><br><span class="line">#抓取物理内存free值（以追加的方式写入文件&gt;&gt;）   </span><br><span class="line">echo Mem-free: &#96;free -m | grep Mem | awk &#39;&#123;print $4&#125;&#39;&#96;M &gt;&gt; &#x2F;scripts&#x2F;mem-free.txt  </span><br><span class="line">  </span><br><span class="line">#抓取缓冲区的free值（以追加的方式写入文件&gt;&gt;）   </span><br><span class="line">echo buffers&#x2F;cache-free: &#96;free -m | grep - | awk &#39;&#123;print $4&#125;&#39;&#96;M &gt;&gt; &#x2F;scripts&#x2F;buffers-free.txt  </span><br><span class="line">  </span><br><span class="line">#抓取Swap分区free值（以追加的方式写入文件&gt;&gt;）   </span><br><span class="line">echo Swap-free: &#96;free -m | grep Swap | awk &#39;&#123;print $4&#125;&#39;&#96;M &gt;&gt; &#x2F;scripts&#x2F;swap-free.txt  </span><br><span class="line">  </span><br><span class="line">#逐行连接上面的时间和内存相关行数据（每次重新写入文件&gt;）   </span><br><span class="line">paste &#x2F;scripts&#x2F;date-time.txt &#x2F;scripts&#x2F;mem-free.txt &#x2F;scripts&#x2F;buffers-free.txt &#x2F;scripts&#x2F;swap-free.txt &gt; &#x2F;scripts&#x2F;freemem.txt  </span><br><span class="line">  </span><br><span class="line"># chmod a+x &#x2F;scripts&#x2F;free-mem.sh  </span><br><span class="line"># &#x2F;scripts&#x2F;free-mem.sh  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>4、查看内存监控的结果文件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># cat &#x2F;scripts&#x2F;freemem.txt  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>5、编写free结果文件邮件发送脚本：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"># vim &#x2F;scripts&#x2F;sendmail-mem.sh  </span><br><span class="line">  </span><br><span class="line">#!&#x2F;bin&#x2F;bash   </span><br><span class="line">#把生成的freemem.txt文件通过邮件发送给用户  </span><br><span class="line">  </span><br><span class="line">#提取本服务器的IP地址信息   </span><br><span class="line">IP&#x3D;&#96;ifconfig eth0 | grep &quot;inet addr&quot; | cut -f 2 -d &quot;:&quot; | cut -f 1 -d &quot; &quot;&#96;  </span><br><span class="line">  </span><br><span class="line">#提取当前日期时间   </span><br><span class="line">today&#x3D;&#96;date -d &quot;0 day&quot; +%Y年%m月%d日&#96;  </span><br><span class="line">  </span><br><span class="line">#发送内存监控结果邮件   </span><br><span class="line">echo &quot;这是$IP服务器$today的内存监控报告，请下载附件。&quot; | mutt -s &quot;$IP服务器$today内存监控报告&quot; -a &#x2F;scripts&#x2F;freemem.txt test@126.com  </span><br><span class="line">  </span><br><span class="line"># chmod a+x &#x2F;scripts&#x2F;sendmail-mem.sh  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>三、监控系统交换分区Swap的情况，当使用超过80%的时候发告警邮件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"># vim &#x2F;scripts&#x2F;swap-warning.sh  </span><br><span class="line">  </span><br><span class="line">#!&#x2F;bin&#x2F;bash  </span><br><span class="line">  </span><br><span class="line">#提取本服务器的IP地址信息   </span><br><span class="line">IP&#x3D;&#96;ifconfig eth0 | grep &quot;inet addr&quot; | cut -f 2 -d &quot;:&quot; | cut -f 1 -d &quot; &quot;&#96;  </span><br><span class="line">  </span><br><span class="line">#系统分配的交换分区总量   </span><br><span class="line">swap_total&#x3D;&#96;free -m | grep Swap | awk &#39;&#123;print $2&#125;&#39;&#96;  </span><br><span class="line">  </span><br><span class="line">#当前剩余的交换分区free大小   </span><br><span class="line">swap_free&#x3D;&#96;free -m | grep Swap | awk &#39;&#123;print $4&#125;&#39;&#96;  </span><br><span class="line">  </span><br><span class="line">#当前已使用的交换分区used大小   </span><br><span class="line">swap_used&#x3D;&#96;free -m | grep Swap | awk &#39;&#123;print $3&#125;&#39;&#96;  </span><br><span class="line">  </span><br><span class="line">if ((swap_used !&#x3D; 0)); then   </span><br><span class="line">  </span><br><span class="line">#如果交换分区已被使用，则计算当前剩余交换分区free所占总量的百分比，用小数来表示，要在小数点前面补一个整数位0   </span><br><span class="line">swap_per&#x3D;0&#96;echo &quot;scale&#x3D;2;$swap_free&#x2F;$swap_total&quot; | bc&#96;  </span><br><span class="line">  </span><br><span class="line">#设置交换分区的告警值为20%(即使用超过80%的时候告警)。  </span><br><span class="line">swap_warn&#x3D;0.20  </span><br><span class="line">  </span><br><span class="line">#当前剩余交换分区百分比与告警值进行比较（当大于告警值(即剩余20%以上)时会返回1，小于(即剩余不足20%)时会返回0 ）   </span><br><span class="line">swap_now&#x3D;&#96;expr $swap_per &gt; $swap_warn&#96;  </span><br><span class="line">  </span><br><span class="line">#如果当前交换分区使用超过80%（即剩余小于20%，上面的返回值等于0），立即发邮件告警   </span><br><span class="line">if (($swap_now &#x3D;&#x3D; 0)); then   </span><br><span class="line">echo &quot;$IP服务器swap交换分区只剩下 $swap_free M 未使用，剩余不足20%，使用率已经超过80%，请及时处理。&quot; | mutt -s &quot;$IP 服务器内存告警&quot; test@126.com  </span><br><span class="line">fi   </span><br><span class="line">  </span><br><span class="line">fi   </span><br><span class="line">  </span><br><span class="line"># chmod a+x &#x2F;scripts&#x2F;swap-warning.sh  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>四、加入任务计划：内存每十分钟检测一次，有告警则立即发邮件(十分钟发一次)，内存检测结果邮件每天早上8点发一次</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># crontab -e  </span><br><span class="line">  </span><br><span class="line">*&#x2F;10 * * * * &#x2F;scripts&#x2F;free-mem.sh   </span><br><span class="line">*&#x2F;10 * * * * &#x2F;scripts&#x2F;swap-warning.sh   </span><br><span class="line">0 8 * * * &#x2F;scripts&#x2F;sendmail-mem.sh  </span><br><span class="line">  </span><br><span class="line"># service crond restart  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><em>转自：ITPUB技术小栈</em>  </p>
<p><img src=""></p>
<p><strong>**</strong>|<strong>**</strong> <strong>**</strong>公众号专属福利 1**<strong>** ****</strong>|<strong>**</strong> </p>
<p><strong>**</strong>| 2020全新专题实战教程限时1.99元 |<strong>**</strong> </p>
<p><strong><strong>****</strong></strong>|<strong>**</strong>识**<strong><strong>**</strong></strong>别获取**<strong><strong>**</strong></strong>课程**<strong><strong>**</strong></strong>邀请好友听课即可返现9**<strong><strong><strong><strong><strong><strong><strong><strong>**</strong></strong></strong></strong></strong></strong></strong></strong>9%|<strong><strong><strong><strong>**</strong></strong></strong></strong></p>
<p><strong><strong>****</strong></strong>|<strong><strong><strong><strong>**</strong></strong></strong></strong>如不分享也可识别海报中二维码单独购买 |<strong>**</strong> </p>
<p><img src=""></p>
<p><img src=""></p>
<p><img src=""></p>
<p><img src=""></p>
<p><img src=""></p>
<p><img src=""></p>
<p>以docker为首的容器技术被称之为云计算时代的未来，谁掌握了微服务容器技术，谁就掌握了未来的核心技术，锁定10月31日晚20:00，理论结合实战带你学好docker！</p>
<p><img src=""></p>
<p>作者：hrs219 </p>
<p>链接：<a target="_blank" rel="noopener" href="http://huangrs.blog.51cto.com/2677571/788379">http://huangrs.blog.51cto.com/2677571/788379</a></p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/linux/%E5%88%A9%E7%94%A8%20Shell%20%E8%84%9A%E6%9C%AC%E5%AE%9E%E7%8E%B0%E9%82%AE%E4%BB%B6%E7%9B%91%E6%8E%A7%20Linux%20%E7%B3%BB%E7%BB%9F%E7%9A%84%E5%86%85%E5%AD%98/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/" rel="tag">linux</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/linux/%E5%88%86%E4%BA%ABLinux%E5%86%85%E5%AD%98%E5%8D%A0%E7%94%A8%E5%87%A0%E4%B8%AA%E6%A1%88%E4%BE%8B/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            分享Linux内存占用几个案例.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/linux/%E6%80%8E%E4%B9%88%E7%90%86%E8%A7%A3linux%E7%9A%84%E5%B9%B3%E5%9D%87%E8%B4%9F%E8%BD%BD%E5%8F%8A%E5%B9%B3%E5%9D%87%E8%B4%9F%E8%BD%BD%E9%AB%98%E5%90%8E%E7%9A%84%E6%8E%92%E6%9F%A5%E5%B7%A5%E5%85%B7/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">怎么理解linux的平均负载及平均负载高后的排查工具.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>